package com.voicechat.firstmet.fragment;

import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.voicechat.firstmet.R;
import com.voicechat.firstmet.activity.PublishPhotoActivity;
import com.voicechat.firstmet.base.BaseFragment;
import com.voicechat.firstmet.view.NoScrollViewPager;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @ProjectName: FirstMet
 * @Package: com.voicechat.firstmet.fragment_shar_girls
 * @ClassName: ShareGirlsFragment
 * @Description: 隐约    ------共享秀照
 * @Author: ljp
 * @CreateDate: 2019/1/4 19:44
 * @Version: 1.0
 */
public class SharePictureFragment extends BaseFragment {

    @BindView(R.id.floatin_button)
    ImageView floatinButton;
    @BindView(R.id.tv_comm_hote)
    TextView tvCommHote;
    @BindView(R.id.tv_comm_new)
    TextView tvCommNew;
    @BindView(R.id.view_page)
    NoScrollViewPager viewPage;
    private ArrayList<Fragment> fragments;
    private MyAdapter mAdapter;

    @Override
    protected int loadLayout() {
        return R.layout.fragment_share_picture;
    }

    @Override
    protected void initLayout(Bundle savedInstanceState) {
        ButterKnife.bind(this, view);
        initView();
    }

    public static SharePictureFragment newInstance() {
        SharePictureFragment shareGirlsFragment = new SharePictureFragment();
        return shareGirlsFragment;
    }

    /**
     * @return
     * @method
     * @description 数据控件实例化
     * @date: 2019/1/4 20:00
     * @author: ljp
     */
    private void initView() {
        initViewPager();
    }

    private void initViewPager() {
        fragments = new ArrayList<>();
        fragments.add(SharePhotoChildFragment.newInstance(0));
        fragments.add(SharePhotoChildFragment.newInstance(1));
        mAdapter = new MyAdapter(getChildFragmentManager());
        viewPage.setAdapter(mAdapter);
        viewPage.addOnAdapterChangeListener(new ViewPager.OnAdapterChangeListener() {
            @Override
            public void onAdapterChanged(@NonNull ViewPager viewPager, @Nullable PagerAdapter pagerAdapter, @Nullable PagerAdapter pagerAdapter1) {

            }
        });
        viewPage.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int i, float v, int i1) {
            }

            @Override
            public void onPageSelected(int i) {
                if (i == 0){
                    clearSelection();
                    tvCommNew.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
                }else {
                    clearSelection();
                    tvCommHote.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
                }

            }

            @Override
            public void onPageScrollStateChanged(int i) {

            }
        });
    }

    @OnClick({R.id.tv_comm_new, R.id.tv_comm_hote, R.id.floatin_button})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tv_comm_new:
                clearSelection();
                viewPage.setCurrentItem(0);
                tvCommNew.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
                break;
            case R.id.tv_comm_hote:
                clearSelection();
                viewPage.setCurrentItem(1);
                tvCommHote.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
                break;
           // 发布共享闺蜜
            case R.id.floatin_button:
                context.startActivity(new Intent(activity, PublishPhotoActivity.class));
                break;
        }
    }
    @Override
    protected void clearSelection() {//清空底部Tab的选中状态,当点击的时候再自定义选中Tab的状态
        super.clearSelection();
        tvCommHote.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
        tvCommNew.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
    }
    private class MyAdapter extends FragmentStatePagerAdapter {

        public MyAdapter(FragmentManager fm) {
            super(fm);
            // TODO Auto-generated constructor stub
        }

        @Override
        public Fragment getItem(int arg0) {
            // TODO Auto-generated method stub
            return fragments.get(arg0);
        }

        @Override
        public int getCount() {
            // TODO Auto-generated method stub
            return fragments.size();
        }

    }


}
